//
//  HXNavigationController.m
//  KD
//
//  Created by Hubery on 16/1/29.
//  Copyright © 2016年 ifly. All rights reserved.
//

#import "HXNavigationController.h"

@interface HXNavigationController ()

@end

@implementation HXNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    //设置navigationBar阴影
    if ([self.navigationBar respondsToSelector:@selector(setBackgroundImage:forBarMetrics:)]){
        [[UINavigationBar appearance] setBarTintColor:[UIColor whiteColor]];
        self.navigationBar.layer.masksToBounds = NO;
//        self.navigationBar.layer.shadowOffset = CGSizeMake(0, 3);
//        self.navigationBar.layer.shadowOpacity = 0.6;
//        self.navigationBar.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.navigationBar.bounds].CGPath;
    }
}


+(void)initialize
{
    UINavigationBar *bar = [UINavigationBar appearance];
    NSMutableDictionary *md = [NSMutableDictionary dictionary];
    md[NSFontAttributeName] = [UIFont boldSystemFontOfSize:19];
    md[NSForegroundColorAttributeName] = [UIColor blackColor];
    [bar setTitleTextAttributes:md];
    
    
    UIBarButtonItem *appearance = [UIBarButtonItem appearance];
    //普通
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    dict[NSForegroundColorAttributeName] = MAINCOLOR;
    [appearance setTitleTextAttributes:dict forState:UIControlStateNormal];
    //高亮
    NSMutableDictionary *hightDict = [NSMutableDictionary dictionary];
    hightDict[NSForegroundColorAttributeName] = [UIColor whiteColor];
    [appearance setTitleTextAttributes:hightDict forState:UIControlStateHighlighted];
    //不能点
    NSMutableDictionary *disableDict = [NSMutableDictionary dictionary];
    disableDict[NSForegroundColorAttributeName] = [UIColor lightGrayColor];
    [appearance setTitleTextAttributes:disableDict forState:UIControlStateDisabled];
}


- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated
{
    if (self.viewControllers.count > 0) { // 如果现在push的不是栈底控制器(最先push进来的那个控制器)
        viewController.hidesBottomBarWhenPushed = YES;
        UIButton *backButton=[[UIButton alloc]init];
        // 设置返回图片
        [backButton setImage:[UIImage imageNamed:@"nav_back"] forState:UIControlStateNormal];
        backButton.contentMode = UIViewContentModeLeft;
        backButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        // [button sizeToFit];//让按钮大小跟随内容
        // 让按钮的内容往左边偏移10
        backButton.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
        [backButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
        backButton.frame=CGRectMake(0, 0,37,90);
        viewController.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithCustomView:backButton];
    }
    [super pushViewController:viewController animated:animated];
}

- (void)back {
    [self popViewControllerAnimated:YES];
}

@end
